from bokeh.models import Select, CustomJS, ColumnDataSource
from bokeh.layouts import column
from numpy import number

x_value = 'goals'
y_value = 'birth_month_number'

full_source = ColumnDataSource(nhl_player_stats_team_df)

source = ColumnDataSource(
    data=dict(
        x=nhl_player_stats_team_df[x_value],
        y=nhl_player_stats_team_df[y_value],
    )
)

plot = figure(width=400, height=200, title="test")
plot.circle(
    'x', 
    'y', 
    source=source, 
    fill_alpha=0.2,
    size=1
)


numeric_cols = nhl_player_stats_team_df.select_dtypes([number]).columns.tolist()
x_select = Select(title="X Axis", options=numeric_cols, value=x_value)
x_select.js_on_change("value", CustomJS(args=dict(source=source, data=full_source), code="""
    console.log(`this is the selected value: ${this.value}`);
    console.log(source.data['x'])
    console.log(data.data)
    source.data['x'] = data.data[this.value]
    source.change.emit();
"""))
layout = column(x_select, plot)

output_file('test.html')

show(layout)
output_notebook()
x_value = 'goals'
y_value = 'birth_month'
nhl_player_stats_team_df = nhl_player_stats_team_df.sort_values(by='birth_month_number')
df = nhl_player_stats_team_df[[
    y_value, 
    x_value, 
]]

categories = nhl_player_stats_team_df[y_value].unique().tolist()

# find the quartiles and IQR for each category
groups = df.groupby(y_value)
q1 = groups.quantile(q=0.25)
q2 = groups.quantile(q=0.5)
q3 = groups.quantile(q=0.75)
iqr = q3 - q1
upper = q3 + 1.5*iqr
lower = q1 - 1.5*iqr

# if lower bound is less than zero, zero it
def greaterThanZero(x):
    return x if (x > 0) else 0
lower[x_value] = lower[x_value].apply(greaterThanZero)
p = figure(width=800, height=400, y_range=categories)

for month in categories:
    p.hbar(
        y=[month], 
        height=0.6,
        left=q1[x_value][month], 
        right=q2[x_value][month],
        fill_color="#E08E79", 
        legend_label=month
    )
    p.hbar(
        y=[month], 
        height=0.6,
        left=q3[x_value][month], 
        right=q2[x_value][month],
        fill_color="#E08E79", 
        legend_label=month
    )
    p.segment(x0=lower[x_value][month], y0=[month], x1=q1[x_value][month],y1=[month],legend_label=month)
    p.segment(x0=q3[x_value][month], y0=[month], x1=upper[x_value][month],y1=[month],legend_label=month)
    p.rect(x=lower[x_value][month], y=[month], width=0.1, height=0.8,legend_label=month)
    p.rect(x=q2[x_value][month], y=[month], width=0.1, height=0.8,legend_label=month)
    p.rect(x=upper[x_value][month], y=[month], width=0.1, height=0.8,legend_label=month)
    
p.legend.click_policy = "hide"
p.legend.background_fill_alpha = 0.3

# show the results
show(p)
#q1.index.values
Loading BokehJS ...
<!DOCTYPE html> Bokeh Plot